﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TurmaLib.Basic;
using TurmaLib.RegraTurma;
using TurmaLib.Repositorio;
using System.Data;

namespace TurmaService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        RegraTurma regTurma = new RegraTurma();
        RepositorioTurma repTurma = RepositorioTurma.getInstancia();

        [WebMethod]
        public void incluirTurma(Turma novaTurma)
        {
            try
            {
               // regTurma.validarTurma(novaTurma);
               // regTurma.pesquisarTurma(novaTurma);
                repTurma.incluirTurma(novaTurma);
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            catch (System.Data.SqlClient.SqlException)
            {
                throw new ArgumentException("Erro de comando sql");
            }
        }



        [WebMethod]
        public void alterarTurma(Turma antiga, Turma nova)
        {
            try
            {
                repTurma.alterar(antiga, nova);
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            catch (System.Data.SqlClient.SqlException)
            {
                throw new ArgumentException("Erro de comando sql");
            }
        }

        [WebMethod]
        public List<Funcionario> pesquisarProfessor(Turma turma)
        {
            try
            {
                return repTurma.pesquisarProfessores(turma);
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            catch (System.Data.SqlClient.SqlException)
            {
                throw new ArgumentException("Erro de comando sql");
            }
        }

        [WebMethod]
        public void excluirTurma(Turma turma)
        {

        }


        [WebMethod]
        public List<Serie> listarSeries()
        {
            try
            {
                return RepositorioTurma.getInstancia().listarSeries();
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
        }

        [WebMethod]
        public List<Funcionario> listarFuncionarios()
        {
            try
            {
                return RepositorioTurma.getInstancia().listarFuncinarios();
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
        }

         [WebMethod]
         public List<Turma> listaTotal()
         {
             try
             {
                 return RepositorioTurma.getInstancia().listaTotal();
             }
             catch (ArgumentException ex)
             {
                 throw ex;
             }
         }
    }
}